Tests for new `package.build` behavior
authorPaul Woolcock <paul@woolcock.us>
Fri, 2 Dec 2016 04:01:51 +0000 (23:01 -0500)
committerPaul Woolcock <paul@woolcock.us>
Fri, 2 Dec 2016 19:57:03 +0000 (14:57 -0500)
tests/build-script.rs

index 46d8e144063b0f57f12e3da897b413c41af8cc17..8524eb95072c4b4ac170c678b21b2d2ddd9ad971 100644 (file)
@@ -2334,3 +2334,74 @@ fn switch_features_rerun() {
     assert_that(build.cargo("run").arg("-v").arg("--features=foo"),
                 execs().with_status(0).with_stdout("foo\n"));
 }
+
+#[test]
+fn assume_build_script_when_build_rs_present() {
+    let p = project("builder")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "builder"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() {
+                println!(include_str!(concat!(env!("OUT_DIR"), "/output")));
+            }
+        "#)
+        .file("build.rs", r#"
+            use std::env;
+            use std::fs::File;
+            use std::io::Write;
+            use std::path::Path;
+
+            fn main() {
+                let out_dir = env::var_os("OUT_DIR").unwrap();
+                let out_dir = Path::new(&out_dir).join("output");
+                let mut f = File::create(&out_dir).unwrap();
+                f.write_all(b"foo").unwrap();
+            }
+        "#);
+    p.build();
+
+    assert_that(p.cargo("run").arg("-v"),
+                execs().with_status(0).with_stdout("foo\n"));
+}
+
+#[test]
+fn if_build_set_to_false_dont_tread_build_rs_as_build_script() {
+    let p = project("builder")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "builder"
+            version = "0.0.1"
+            authors = []
+            build = false
+        "#)
+        .file("src/main.rs", r#"
+            use std::path::Path;
+            fn main() {
+                let f = env!("OUT_DIR");
+                assert!(
+                    ! Path::new(f).join("output").exists()
+                )
+            }
+        "#)
+        .file("build.rs", r#"
+            use std::env;
+            use std::fs::File;
+            use std::io::Write;
+            use std::path::Path;
+
+            fn main() {
+                let out_dir = env::var_os("OUT_DIR").unwrap();
+                let out_dir = Path::new(&out_dir).join("output");
+                let mut f = File::create(&out_dir).unwrap();
+                f.write_all(b"foo").unwrap();
+            }
+        "#);
+    p.build();
+
+    assert_that(p.cargo("run").arg("-v"),
+                execs().with_status(0));
+}